package name.zxw.rabbitmq.controller;

import lombok.extern.slf4j.Slf4j;
import name.zxw.rabbitmq.config.ConfirmConfig;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhangxinwang
 * @date 2022/6/28 11:10
 */
@Slf4j
@RestController
@RequestMapping("/confirm")
public class ProducerController {

    private final RabbitTemplate rabbitTemplate;

    @Autowired
    public ProducerController(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    // http://localhost:8080/confirm/sendMessage/testContext
    @GetMapping("/sendMessage/{msg}")
    public void sendMessage(@PathVariable("msg") String message) {
        log.info("发送消息内容:{}", message);
        rabbitTemplate.convertAndSend(ConfirmConfig.CONFIRM_EXCHANGE_NAME, ConfirmConfig.CONFIRM_ROUTING_KEY, message + "1", new CorrelationData("1"));
        rabbitTemplate.convertAndSend(ConfirmConfig.CONFIRM_EXCHANGE_NAME, ConfirmConfig.CONFIRM_ROUTING_KEY + "123", message + "2", new CorrelationData("2"));
    }

    //Tree appearance
    //compact middle packages

    //Create a JDK dynamic proxy implementing all interfaces exposed by the class of the target object.
    //Create a class-based proxy (uses CGLIB).
}
